$(function () {

    let data = ["【川菜】", "【粤菜】", "【魯菜】", "【闽菜】", "【湘菜】", "【鄂菜】"];
    setCuisineData(data);
    // findById();
});

function setCuisineData(data) {
    let html = '';
    for (let i = 0; i < data.length; i++) {
        html += '<div onclick="changeCuisine(this)" id="cuisine' + i + '">' + data[i] + '</div>';
    }
    $("#cuisine").html(html);
    //但页面加载完成我们需要赋值
    //1.对菜系赋值
    //2.对当前菜品是属于哪一个菜系进行赋值
    $("#cuisine"+caixiId).css("background-color", "red");
}

function changeCuisine(obj) {
    let cuisine = $("#cuisine>div");
    console.log(cuisine)
    for (let i = 0; i < cuisine.length; i++) {
        $(cuisine[i]).css("background-color", "");
    }
    $(obj).css("background-color", "red");
}
let caixiId=0;
function findById() {
    let id = sessionStorage.getItem("productId");
    let caixiId = sessionStorage.getItem("caixiID");
    let caixi = $("#caixi>div");
    for (let i = 0; i < caixi.length; i++) {
        $(caixi)[i].remove('layui-btn-class');
        $(caixiId).addClass('layui-btn-class');
    }
    // $("#caixiid"+caixiId).css("backgroundcolor","red");
    let data = myAjax("/findById", {id: id}, "get");
    setData(data.list);
}

function setData(data) {
    if (data.length == 2) {

        if (data[1].id == sessionStorage.getItem("productId")) {
            $("#productData").html(data[1].content);
            $("#lastData").html(data[0].title);
            $("#nextData").html("无");

        }
        if (data[0].id == sessionStorage.getItem("productId")) {
            $("#productData").html(data[0].content);
            $("#lastData").html("无");
            $("#nextData").html(data[1].title);

        }

    }
    if (data.length == 1) {
        $("#productData").html(data[0].content);
        $("#lastData").html("无");
        $("#nextData").html("无");

    }
    if (data.length == 3) {
        $("#productData").html(data[1].content);
        $("#lastData").html(data[0].title);
        $("#nextData").html(data[2].title);
    }
}